/**
 * Created with IntelliJ IDEA.
 *
 * @author: cxs
 * @date: 2023/7/5
 * @time: 11:22
 * @className：MenuServiceImpl
 * @description：
 */
package com.bailan.sys.service.impl;

import com.bailan.common.util.DataGridView;
import com.bailan.sys.domain.Menu;
import com.bailan.sys.mapper.MenuMapper;
import com.bailan.sys.service.MenuService;
import com.bailan.sys.vo.MenuVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public List<Menu> queryAllMenuForList(MenuVo menuVo) {
        return menuMapper.queryAllMenu(menuVo);
    }

    @Override
    public DataGridView queryAllMenu(MenuVo menuVo) {
        Page<Object> page = PageHelper.startPage(menuVo.getPage(),menuVo.getLimit());
        List<Menu> data = this.menuMapper.queryAllMenu(menuVo);
        return new DataGridView(page.getTotal(),data);
    }

    /**
     * 添加菜单
     *
     * @param menuVo
     */
    @Override
    public void addMenu(MenuVo menuVo) {
        this.menuMapper.insertMenu(menuVo);
    }

    /**
     * 修改菜单
     *
     * @param menuVo
     */
    @Override
    public void updateMenu(MenuVo menuVo) {
        this.menuMapper.updateMenu(menuVo);
    }

    @Override
    public void deleteMenu(MenuVo menuVo) {
        this.menuMapper.deleteMenu(menuVo.getId());
    }

    /**
     * 查找子节点
     *
     * @param pid
     * @return
     */
    @Override
    public Integer queryMenuByPid(Integer pid) {
        return this.menuMapper.queryMenuByPid(pid);
    }

}
